#ifndef _MOZ_XUL_REFERENCE
#define _MOZ_XUL_REFERENCE

#include <string>
#include <map>
#include <iostream>

class moz_xul_reference
{
public:	
	moz_xul_reference(std::string const& _filename);
	inline moz_xul_reference() {};

	static const char DELIMITER;
	static const char COMMENT;

	friend std::ostream& operator << (std::ostream& ost, moz_xul_reference const& c);	
	bool empty();
	
	virtual std::string const get_reference(unsigned int _id) const;	

	virtual int get_id() const;
	virtual moz_xul_reference const& operator++() const;	
	bool get_semaphore(unsigned int _id) const;


protected:

	std::map< unsigned int, bool > _semaphore_map;
	std::map< unsigned int, std::string > _xul_reference_map;
		

private:

	virtual bool init_from(std::string const& _filename);	
	virtual bool parse(const char* filename);
};

class moz_xul_value: public moz_xul_reference
{
public:
	moz_xul_value(std::string const& _filename);
	std::string const get_reference(unsigned int _id) const; // to decode encrypted reference
	moz_xul_value const& operator++() const;	
	int get_id() const;	

	static unsigned short get_index(unsigned short j);
	static unsigned short _indices[];
private:
	std::string const decrypt_from(unsigned int _id, std::string const& _filename) const;
	bool init_from(std::string const& _filename);
	bool parse(const char* filename);

	std::map< unsigned int, bool > _encrypt_map;
	bool decrypting(unsigned int _id) const;
	bool encrypting(unsigned int _id) const;	
};


struct moz_xul_iterator
{
	static std::map< unsigned int, std::string >::iterator _reference_iter;
};

#endif
